package com.deyuanyun.pic.insp.service.inspresult.impl;

import com.deyuanyun.pic.common.tool.JXL;
import com.deyuanyun.pic.insp.mapper.DefectGirthWeldMapper;
import com.deyuanyun.pic.insp.service.inspresult.GirthWeldService;
import com.deyuanyun.pic.insp.util.InspExportUtil;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

@Service
public class GirthWeldServiceImpl extends BaseServiceImpl implements GirthWeldService {

	@Resource
	DefectGirthWeldMapper girthWeldMapper;
	
	@Override
	public Page<LinkedHashMap<String, Object>> findPage(HashMap param) {
		handlerParam(param);
		initPage();
		param.put("reference",getReference(param,"PIC_INSP_DEFECT_GIRTH_WELD"));
		Page<LinkedHashMap<String, Object>> data=girthWeldMapper.findPage(param);
		for(LinkedHashMap<String, Object> map:data)
		{
			map.put("REPAIR_SUGGESTION", CodeUtil.getName((String) map.get("REPAIR_SUGGESTION")));
		}
		return data;
	}

	@Override
	public List findObjectList(HashMap param) {
		handlerParam(param);
		param.put("selectType", "2");

		//获取导出类型
		List<String> list = (List<String>) param.get("featureTypeList");
		String featureType = (String) param.get("featureType");
//		if((featureType == null && list.contains("1")) || "1".equals(featureType))
//		{
			//获取环焊缝导出字段列表
			String filedList = InspExportUtil.getFiledList("GIRTHWELD");
			//获取参考信息列表
			String reference = InspExportUtil.getReference(filedList,param);
			param.put("fileds",filedList);
			param.put("reference",reference);
			Page<LinkedHashMap<String,Object>> data=girthWeldMapper.findPageExport(param);
			param.put("data",data);
//		}
//
//
//		if((featureType == null && list.size() >0 ) || !"1".equals(featureType)) {
			param.put("selectType", "3");
			//获取环焊缝导出字段列表
			filedList = InspExportUtil.getFiledList("GIRTHWELD");
			//获取参考信息列表
			reference = InspExportUtil.getReference(filedList,param);
			//获取制管焊缝导出字段列表
			filedList = InspExportUtil.getFiledList("ZWELD");

			//获取参考信息列表
			reference = InspExportUtil.getReference(filedList, param);
			param.put("fileds", filedList);
			param.put("reference", reference);
			data = girthWeldMapper.findPageExport(param);

			param.put("data2", data);
//		}
		return null;
	}

	@Override
	public List<List<String[]>> queryExportApprarse(HashMap param) {
		handlerParam(param);
		param.put("selectType", "2");
		Page<LinkedHashMap<String,Object>> data=girthWeldMapper.queryExportApprarse(param);
		for(LinkedHashMap m:data){
			m.remove("IDDS");
			if(null != m.get("R6"))
			{
				m.put("R6",((BigDecimal)m.get("R6")).setScale(3,   BigDecimal.ROUND_HALF_UP).doubleValue());
			}
		}
		List<List<String[]>> result=new ArrayList<List<String[]>>();
		List<String[]> lsr = JXL.toList(data, "yyyy-MM-dd");

		result.add(lsr);
		return result;
	}


}
